package com.hliushi.hotel.config;

import com.hliushi.hotel.constants.MqConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMq配置
 *
 * @author llhuang10
 * @date 2021/9/9 21:14
 */
@Configuration
public class MqConfig {


    /**
     * 注入交换机
     */
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(MqConstants.HOTEL_EXCHANGE, true, true);
    }

    /**
     * 注入 新建或修改队列
     */
    @Bean
    public Queue insertQueue() {
        return new Queue(MqConstants.HOTEL_INSERT_QUEUE, true);
    }

    /**
     * 注入 删除队列
     */
    @Bean
    public Queue deleteQueue() {
        return new Queue(MqConstants.HOTEL_DELETE_QUEUE, true);
    }


    /**
     * 绑定新增队列
     */
    @Bean
    public Binding insertQueueBinding() {
        return BindingBuilder
                .bind(insertQueue())
                .to(topicExchange())
                .with(MqConstants.HOTEL_INSERT_KEY);
    }

    /**
     * 绑定删除队列
     */
    @Bean
    public Binding deleteQueueBinding() {
        return BindingBuilder
                .bind(deleteQueue())
                .to(topicExchange())
                .with(MqConstants.HOTEL_DELETE_KEY);
    }
}
